import request from '@/utils/request'


/**
 * 获取采购列表
 * @param params
 * @returns {Promise | Promise<unknown>}
 */
export function getProcureGoodsList(params = {}){
  return request({
    url: `/procure/getProcureGoodsList`,
    method: 'get',
    params
  })
}

/**
 *
 * @param suitId
 * @returns {Promise | Promise<unknown>}
 */
export function getGoodsProcure(suitId){
  return request({
    url: `/procure/getGoodsProcure/${suitId}`,
    method: 'get',
  });
}


/**
 * 通过接口获取阿里的商品信息
 * @param params
 * @returns {Promise | Promise<unknown>}
 */
export function getAliGoodsByLink(params){
  return request({
    url: `/procure/getAliGoodsByLink`,
    method: 'get',
    params,
    handleError: true,
  })
}

/**
 * 保存配置
 * @param data
 * @returns {Promise | Promise<unknown>}
 */
export function saveProcure(data){
  return request({
    url : `/procure/saveProcure`,
    method: 'post',
    data,
  })
}

/**
 * 获取预览订单
 * @param params
 * @returns {Promise | Promise<unknown>}
 */
export function getPreviewOrder(params){
  return request({
    url: `/procure/getPreviewOrder`,
    method: 'get',
    params,
    handleError: true,
  })
}

/**
 * 确认采购单
 * @param data
 * @returns {Promise | Promise<unknown>}
 */
export function createProcureOrder(data){
  return request({
    url: `/procure/createProcureOrder`,
    method: 'post',
    data,
    handleError: true,
  })
}

/**
 * 获取采购单号列表
 * @param params
 * @returns {Promise | Promise<unknown>}
 */
export function getProcureOrderList(params = {}){
  return request({
    url: '/procure/getProcureOrderList',
    method: 'get',
    params,
  })
}

/**
 * 获取采购单详情
 * @param procureOrder
 * @param handleError
 * @returns {Promise<unknown>}
 */
export function getProcureOrderInfo(procureOrder,handleError = false){
  return request({
    url: `/procure/getProcureOrderInfo/${procureOrder}`,
    method: 'get',
    handleError,
  })
}

/**
 * 获取订单的支付链接
 * @param data
 * @returns {Promise<unknown>}
 */
export function getOrderPayUrl(data){
  return request({
    url: `/procure/getOrderPayUrl`,
    method: 'post',
    data,
    handleError: true,
  })
}

/**
 * 取消订单
 * @param data
 * @returns {Promise<unknown>}
 */
export function cancelOrder(data){
  return request({
    url: `/procure/cancelAliOrder`,
    method: 'post',
    data,
    handleError: true,
  })
}


/**
 * 获取采购单的预览订单
 * @param params
 * @returns {Promise | Promise<unknown>}
 */
export function getProcureOrderPreviewOrder(params){
  return request({
    url: `/procure/procureOrderPreviewOrder`,
    params,
    method: 'get',
  })
}


/**
 * 取消采购
 * @param data
 * @returns {Promise | Promise<unknown>}
 */
export function cancelProcure(data){
  return request({
    url: `/procure/cancelProcure`,
    method: 'delete',
    data,
  })
}

export function removeProcureOrderId(data){
  return request({
    url: `/procure/removeProcureOrderId`,
    method: 'delete',
    data,
  })
}


export function getProcureHelp(){
  return request({
    url: `/procure/getProcureHelp`,
    method: 'get',
  })
}
